package com.grass.finding.exception;

import com.grass.finding.common.BaseResponse;
import com.grass.finding.common.ErrorCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessException(BusinessException e){
        log.error("businessException:" + e.getMessage(), e);
        return new BaseResponse<>(e);
    }
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeException(RuntimeException e){
        log.error("businessException:" + e.getMessage(), e);
        return new BaseResponse<>(ErrorCode.SYSTEM_ERROR);
    }
}

